
//
//  woDeView.m
//  zhangGuangTianXia
//
//  Created by tangtangchitangtang on 2017/11/6.
//  Copyright © 2017年 tangtangchitangtang. All rights reserved.
//

#import "woDeView.h"
#import "personalViewController.h"

@implementation woDeView

-(void)creatView{
    
    _dic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    
    self.backgroundColor=_LightGrey;
    
    _scrollView=[UIScrollView new];
    [self addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-44);
    }];
    _scrollView.scrollsToTop = NO;
    
    _scrollView.showsVerticalScrollIndicator = FALSE;
    _scrollView.showsHorizontalScrollIndicator = FALSE;
    _scrollView.bounces = NO;
    _scrollView.contentSize = CGSizeMake(0, 700);
    [self creatTopView];
    [self creatOrderView];
    [self creatOperationView];
    [self creatWalletView];
    [self creatOtherView];

    
}
-(void)creatTopView{
    UIView *topView=[UIView new];
    [_scrollView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(0);
        make.width.mas_equalTo(_mainW);
        make.height.mas_equalTo(180);
    }];
    
    UIImageView *imageView=[UIImageView new];
    [topView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
    }];
    imageView.backgroundColor=_tianLanColor;
    imageView.userInteractionEnabled=YES;
    
    UITapGestureRecognizer *personal = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToGeRenZhongXin:)];
    [imageView addGestureRecognizer:personal];
    
    
    UIView *userImage=[UIView new];
    [topView addSubview:userImage];
    [userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(10);
        make.width.height.mas_equalTo(70);
    }];
    userImage.backgroundColor=[UIColor colorWithRed:1 green:1 blue:1 alpha:0.4];
    userImage.layer.cornerRadius=35;

    
    UIImageView *userImgaeView=[UIImageView new];
    [userImage addSubview:userImgaeView];
    [userImgaeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.width.height.mas_equalTo(60);
    }];
    userImgaeView.layer.masksToBounds=YES;
    userImgaeView.layer.cornerRadius=30;
    if (_dic!=nil) {
        NSString *headImg=[_dic objectForKey:@"headImg"];
        NSURL *imageUrl=[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",_addressUrl2,headImg]];
        [userImgaeView sd_setImageWithURL:imageUrl];
    }
    else{
        userImgaeView.backgroundColor=[UIColor redColor];
    
    }
    
    
    if (_dic==nil) {
        UILabel *label=[UILabel new];
        [topView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(userImage);
            make.left.mas_equalTo(userImage.mas_right).mas_equalTo(7);
        }];
        label.text=@"未登录";
        label.font=[UIFont fontWithName:@"CourierNewPS-ItalicMT" size:17];
        
        UIImageView *shangJia=[UIImageView new];
        [topView addSubview:shangJia];
        [shangJia mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(0);
            make.centerY.mas_equalTo(userImage);
            make.height.mas_equalTo(30);
            make.width.mas_equalTo(100);
        }];
        shangJia.backgroundColor=[UIColor whiteColor];

        return;
    }

    
    UILabel *namelabel=[UILabel new];
    [topView addSubview:namelabel];
    [namelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userImage.mas_right).mas_equalTo(10);
        make.centerY.mas_equalTo(userImage).mas_equalTo(-10);
    }];
    namelabel.text=[_dic objectForKey:@"nickName"];
    namelabel.textColor=[UIColor whiteColor];
    namelabel.font=[UIFont systemFontOfSize:16];
    
    UILabel *IDLabe=[UILabel new];
    [topView addSubview:IDLabe];
    [IDLabe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(namelabel);
        make.centerY.mas_equalTo(userImage).mas_equalTo(10);

    }];
    
    NSString *ID=[_dic objectForKey:@"id"];
    
    
    ID=[ID stringByRemovingPercentEncoding];
    
    IDLabe.text=[NSString stringWithFormat:@"ID:%@",ID];
    IDLabe.textColor=[UIColor whiteColor];
    IDLabe.font=[UIFont systemFontOfSize:14];
    IDLabe.alpha=0.8;
    
    UIImageView *shangJia=[UIImageView new];
    [topView addSubview:shangJia];
    [shangJia mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.centerY.mas_equalTo(userImage);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(100);
    }];
    shangJia.backgroundColor=[UIColor whiteColor];
    
    
}
-(void)creatOperationView{


   
    
    UIView *view=[UIView new];
    [_scrollView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(19.3);
        make.width.mas_equalTo(_mainW-38.6);
        make.height.mas_equalTo(61.4);
        make.top.mas_equalTo(150);
    }];
    view.backgroundColor=_tianLanColor;
    view.alpha=0.09;
    
    
    UIView *operationView=[UIView new];
    [_scrollView addSubview:operationView];
    [operationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(_mainW-40);
        make.height.mas_equalTo(60);
        make.top.mas_equalTo(150);
    }];
    operationView.backgroundColor=[UIColor whiteColor];
    operationView.layer.cornerRadius=3;
    
    UILabel *numLabel1=[UILabel new];
    [operationView addSubview:numLabel1];
    [numLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.mas_equalTo(-10);
    }];
    [numLabel1 layoutIfNeeded];
    numLabel1.text=@"206";
    numLabel1.font=[UIFont systemFontOfSize:16];
    numLabel1.textColor=ColorWithRGB(70, 70, 70);
    
    UILabel *label1=[UILabel new];
    [operationView addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(numLabel1);
        make.centerY.mas_equalTo(10);
    }];
    label1.text=@"商品收藏";
    label1.font=[UIFont systemFontOfSize:14];
    label1.textColor=ColorWithRGB(200, 200, 200);
    [label1 layoutIfNeeded];
    
    
    UILabel *numLabel2=[UILabel new];
    [operationView addSubview:numLabel2];
    [numLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo((_mainW-40)/2-40);
        make.centerY.mas_equalTo(-10);
    }];
    [numLabel2 layoutIfNeeded];
    numLabel2.text=@"206";
    numLabel2.font=[UIFont systemFontOfSize:16];
    numLabel2.textColor=ColorWithRGB(70, 70, 70);
    
    UILabel *label2=[UILabel new];
    [operationView addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(numLabel2);
        make.centerY.mas_equalTo(10);
    }];
    label2.text=@"关注店铺";
    label2.font=[UIFont systemFontOfSize:14];
    label2.textColor=ColorWithRGB(200, 200, 200);
    [label2 layoutIfNeeded];
    
    
    
    UILabel *numLabel3=[UILabel new];
    [operationView addSubview:numLabel3];
    [numLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainW-130);
        make.centerY.mas_equalTo(-10);
    }];
    [numLabel3 layoutIfNeeded];
    numLabel3.text=@"206";
    numLabel3.font=[UIFont systemFontOfSize:16];
    numLabel3.textColor=ColorWithRGB(70, 70, 70);
    
    UILabel *label3=[UILabel new];
    [operationView addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(numLabel3);
        make.centerY.mas_equalTo(10);
    }];
    label3.text=@"我的足迹";
    label3.font=[UIFont systemFontOfSize:14];
    label3.textColor=ColorWithRGB(200, 200, 200);
    [label3 layoutIfNeeded];
    
}

-(void)creatOrderView{
    UIView *orderView=[UIView new];
    [_scrollView addSubview:orderView];
    [orderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(_mainW);
        make.top.mas_equalTo(180);
        make.height.mas_equalTo(160);
    }];
    orderView.backgroundColor=[UIColor whiteColor];
    UILabel *orderLabel=[UILabel new];
    [orderView addSubview:orderLabel];
    [orderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(45);
    }];
    orderLabel.text=@"我的订单";
    orderLabel.font=[UIFont systemFontOfSize:18];
    orderLabel.textColor=ColorWithRGB(49, 49, 49);
    [orderLabel layoutIfNeeded];
    
    UIView *xianView=[UIView new];
    [orderView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(orderLabel.mas_bottom).mas_equalTo(15);
        make.height.mas_equalTo(1);
    }];
    xianView.backgroundColor=_LightGrey;
    
    NSArray *nameArr=[NSArray arrayWithObjects:@"待付款",@"待发货",@"待收货",@"退款/售后", nil];
    for (int i=0; i<4; i++) {
        UIView *beiJingView=[UIView new];
        [orderView addSubview:beiJingView];
        [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(i*_mainW*0.25);
            make.width.mas_equalTo(_mainW*0.25);
            make.top.mas_equalTo(xianView.mas_bottom);
            make.bottom.mas_equalTo(0);
        }];
        
        UIImageView *imageview=[UIImageView new];
        [beiJingView addSubview:imageview];
        [imageview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(10);
            make.width.height.mas_equalTo(30);
        }];
        imageview.backgroundColor=_tianLanColor;
        
        
        UILabel *zhuangTaiLabel=[UILabel new];
        [beiJingView addSubview:zhuangTaiLabel];
        [zhuangTaiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(imageview.mas_bottom).mas_equalTo(5);
        }];
        zhuangTaiLabel.text=nameArr[i];
        zhuangTaiLabel.font=[UIFont systemFontOfSize:14];
        zhuangTaiLabel.textColor=ColorWithRGB(200, 200, 200);
    }

}


-(void)creatWalletView{
    UIView *orderView=[UIView new];
    [_scrollView addSubview:orderView];
    [orderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(_mainW);
        make.top.mas_equalTo(350);
        make.height.mas_equalTo(140);
    }];
    orderView.backgroundColor=[UIColor whiteColor];
    UILabel *orderLabel=[UILabel new];
    [orderView addSubview:orderLabel];
    [orderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(10);
    }];
    orderLabel.text=@"我的订单";
    orderLabel.font=[UIFont systemFontOfSize:18];
    orderLabel.textColor=ColorWithRGB(49, 49, 49);
    [orderLabel layoutIfNeeded];
    
    UIView *xianView=[UIView new];
    [orderView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(orderLabel.mas_bottom).mas_equalTo(15);
        make.height.mas_equalTo(1);
    }];
    xianView.backgroundColor=_LightGrey;
    
    NSArray *nameArr=[NSArray arrayWithObjects:@"我的薪酬",@"我的积分",@"推荐会员", nil];
    for (int i=0; i<3; i++) {
        UIView *beiJingView=[UIView new];
        [orderView addSubview:beiJingView];
        [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(i*_mainW/3);
            make.width.mas_equalTo(_mainW/3);
            make.top.mas_equalTo(xianView.mas_bottom);
            make.bottom.mas_equalTo(0);
        }];
        
        UIImageView *imageview=[UIImageView new];
        [beiJingView addSubview:imageview];
        [imageview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(15);
            make.width.height.mas_equalTo(45);
        }];
        imageview.backgroundColor=_tianLanColor;
        
        
        UILabel *zhuangTaiLabel=[UILabel new];
        [beiJingView addSubview:zhuangTaiLabel];
        [zhuangTaiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(imageview.mas_bottom).mas_equalTo(5);
        }];
        zhuangTaiLabel.text=nameArr[i];
        zhuangTaiLabel.font=[UIFont systemFontOfSize:14];
        zhuangTaiLabel.textColor=ColorWithRGB(200, 200, 200);
    }
    
    
}

-(void)creatOtherView{
    
    
    UIView *beiJingView=[UIView new];
    [_scrollView addSubview:beiJingView];
    [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(_mainW);
        make.top.mas_equalTo(500);
        make.height.mas_equalTo(152);
    }];
    beiJingView.backgroundColor=[UIColor whiteColor];
    
    NSArray *nameArr=[NSArray arrayWithObjects:@"物流查询",@"我的评价",@"我的发布", nil];
    for (int i=0; i<3; i++) {
        UIView *view=[UIView new];
        [beiJingView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(_mainW);
            make.top.mas_equalTo(50*i+i);
            make.height.mas_equalTo(50);
        }];
        
        UILabel *label=[UILabel new];
        [view addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.centerY.mas_equalTo(0);
        }];
        label.font=[UIFont systemFontOfSize:16];
        label.textColor=ColorWithRGB(170, 170, 170);
        label.text=nameArr[i];
        
        if (i!=2) {
            UIView *xianView=[UIView new];
            [beiJingView addSubview:xianView];
            [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(view.mas_bottom);
                make.left.mas_equalTo(20);
                make.right.mas_equalTo(0);
                make.height.mas_equalTo(1);
            }];
            xianView.backgroundColor=_LightGrey;
        }
        
        
        
    }

}

-(void)pushToGeRenZhongXin:(UITapGestureRecognizer *)tap{
    
    if (_dic==nil) {
        _loginWithVc(self.viewController);
        return;
    }
    personalViewController *Personal=[[personalViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:Personal];



}
@end
